package net.myspring.common.domain;


import net.myspring.common.mybatis.provider.annotation.GeneratedValue;
import net.myspring.common.mybatis.provider.annotation.GenerationType;
import net.myspring.common.utils.SnowflakeUtils;
import net.myspring.common.utils.StringUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;

import java.io.Serializable;

/**
 * Created by liuj on 2016-07-25.
 */
public class IdEntity<T> implements Serializable {
    private static final long serialVersionUID = -864662154371775680L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected String id;
    @Transient
    protected Boolean selected=true;
    @Transient
    protected Boolean editable=true;
    @Transient
    protected Boolean deletable=true;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Boolean getSelected() {
        return selected;
    }

    public void setSelected(Boolean selected) {
        this.selected = selected;
    }

    public Boolean getEditable() {
        return editable;
    }

    public void setEditable(Boolean editable) {
        this.editable = editable;
    }

    public Boolean getDeletable() {
        return deletable;
    }

    public void setDeletable(Boolean deletable) {
        this.deletable = deletable;
    }

    public Boolean isCreate() {
        return StringUtils.isEmpty(id);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((StringUtils.isEmpty(id)) ? 0 : id.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        IdEntity other = (IdEntity) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        return true;
    }
}